<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			h1{
				text-align: center;
			}
		</style>
	</head>
	<body>
		<h1></h1>
		<script>
			var h1box=document.querySelector("h1");
			var timer=null,timer2=null;
		    var str="abcdefghijk1234567890";
			function getCode(str,len){
				var res="";
				for(var i=0;i<len;i++){
					var index=Math.round(Math.random()*str.length);
					res+=str[index];
				}
				return res;
			}
			
			//打开页面先给一个初始值
			h1box.innerHTML=getCode(str,4);
			
			timer=setInterval(()=>{
				var result=getCode(str,4);
				h1box.innerHTML=result;
			},1000)
			
			timer2=setInterval(()=>{
				clearInterval(timer);
				clearInterval(timer2);
				timer=null;
				timer2=null;
			},3000)
			
		</script>
	</body>
</html>
